package com.sfx.controller;

import com.sfx.domain.ResponseResult;
import com.sfx.domain.dto.AddCommentDto;
import com.sfx.domain.entity.Comment;
import com.sfx.service.CommentService;
import com.sfx.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.sfx.constants.SystemConstants.COMMENT_TYPE_LINK;
import static com.sfx.constants.SystemConstants.COMMENT_TYPE_NORMAL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-07-12
 * Time: 18:28
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论",description = "评论相关接口")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     * 查询评论列表
     * @return
     */
    @ApiOperation(value = "评论列表",notes = "分页查询评论列表")
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId,Integer pageNum,Integer pageSize) {
        return commentService.commentList(COMMENT_TYPE_NORMAL,articleId,pageNum,pageSize);
    }

    @ApiOperation(value = "友链列表",notes = "分页查询友链列表")
    //接口文档配置参数
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId",value = "文档id"),
            @ApiImplicitParam(name = "pageNum",value = "页号"),
            @ApiImplicitParam(name = "pageSize",value = "每页的大小")
    })
    @GetMapping("/linkCommentList")
    public ResponseResult commentLinkList(Long articleId,Integer pageNum,Integer pageSize) {
        return commentService.commentList(COMMENT_TYPE_LINK,articleId,pageNum,pageSize);
    }

    //接口描述配置
    @ApiOperation(value = "添加评论",notes = "增加一条评论到数据库")
    @PostMapping
    public ResponseResult addComment(@RequestBody AddCommentDto commentDto) {
        Comment comment = BeanCopyUtils.copyBean(commentDto, Comment.class);
        return commentService.addComment(comment);
    }
}